package com.songlanyun.modules.cnarea.controller.admin;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.songlanyun.common.config.resttplconfig.RestUtil;
import com.songlanyun.common.utils.custom.HttpUtils;
import com.songlanyun.modules.user.controller.AbstractController;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.cnarea.entity.CnArea;
import com.songlanyun.modules.cnarea.service.CnAreaService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import org.springframework.web.client.RestTemplate;


/**
 * 行政区域
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-13 22:33:46
 */
@RestController
@RequestMapping("admin/cnarea")
public class CnAreaAdminController extends AbstractController {
    @Autowired
    private CnAreaService cnAreaService;

    /**
     * 刷新txlbs数据在本地
     */
    @RequestMapping("/lbs-refresh")
    //@RequiresPermissions("cnarea:cnarea:save")
    public R refresh() {
        //cnAreaService.refresh();
        return R.ok();
    }


    /**
     * 刷新json数据在本地
     */
    @RequestMapping("/lbs-new")
    //@RequiresPermissions("cnarea:cnarea:save")
    public R refreshJson() {
        //cnAreaService.refreshJson();
        return R.ok();
    }

    /**
     * 获取LBS下级（测试用）
     */
    @RequestMapping("/test_child/{code}")
    //@RequiresPermissions("cnarea:cnarea:save")
    public R testChild(@PathVariable("code") String code) {
        JSONArray lbsChild = cnAreaService.getLbsChild(code);
        return R.ok().put("data",lbsChild);
    }

    /**
     * 逆地址解析（坐标位置描述）
     */
    @GetMapping("/get-address/{location}")
    //@RequiresPermissions("cnarea:cnarea:save")
    public R getAddress(@PathVariable("location") String location) {
        JSONObject code = cnAreaService.getAddress(location);
        return R.ok().put("date", code);
    }

    /**
     * 地址解析（地址转坐标）
     */
    @GetMapping("/get-code/{address}")
    //@RequiresPermissions("cnarea:cnarea:save")
    public R getCode(@PathVariable("address") String address) {
        JSONObject code = cnAreaService.getCode(address);
        return R.ok().put("date", code);
    }

}
